# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>
# Contributor: Arvid Norlander <anmaster A_T tele2 d_o_t (ccTLD for Sweden, which is se)>
# Contributor: Patrick McCarty <pnorcks at gmail dot com>

pkgname=tup
pkgver=0.7.11
pkgrel=1
pkgdesc='A fast, file-based build system'
arch=(loong64 x86_64)
url='http://gittup.org/tup/index.html'
license=(GPL2)
depends=(fuse3 pcre)
install=tup.install
source=($pkgname-$pkgver.tar.gz::https://github.com/gittup/tup/archive/v$pkgver.tar.gz)
sha256sums=('be24dff5f1f32cc85c73398487a756b4a393adab5e4d8500fd5164909d3e85b9')

prepare() {
  cd tup-$pkgver

  sed "s/\`git describe\`/$pkgver/" -i src/tup/link.sh
  echo "CFLAGS += $CFLAGS" >> Tuprules.tup
  echo "LDFLAGS += $LDFLAGS" >> Tuprules.tup
}

build() {
  cd tup-$pkgver

  # Clean environment does not allow to use fuse so ./bootstrap does not work
  ./build.sh
  ./build/tup init
  ./build/tup generate runme.sh
  ./runme.sh
}

package() {
  cd tup-$pkgver

  install -d "$pkgdir"/usr/bin "$pkgdir"/usr/share/man/man1 "$pkgdir"/usr/share/vim/vimfiles/{syntax,ftdetect}
  install -m755 -t "$pkgdir"/usr/bin tup
  install -m644 -t "$pkgdir"/usr/share/man/man1 tup.1
  install -m644 -t "$pkgdir"/usr/share/vim/vimfiles/syntax contrib/syntax/tup.vim
  echo 'au BufNewFile,BufRead Tupfile,*.tup setf tup' > "$pkgdir"/usr/share/vim/vimfiles/ftdetect/tup.vim
}
